<!--#include file=..\checkSession.inc-->
<!--#include file="..\RootContent.inc"-->
<!--#include file=..\getFormName.inc-->
<%
	bMa=Request("bMa")
	sort=Request("sort")
	bLoaiVT=Request("bLoaiVT")
	bComm=Request("bComm")	
	bNam=Request("bNam")
	if Request("bPost")="ok" then
		'Save Text
		Select Case bLoaiVT
			Case "1"
				Path=RootContent & "Upload\"& cstr(bNam) &"\Den\Text"
				Path=Path & "\" & bMa & ".VT"
			Case "2"
				Path=RootContent & "Upload\"& cstr(bNam) &"\Di\Text"
'Hien 21_05
				Path=Path & "\" & replace(bMa,"/","_") & ".VT" 
			Case "3"
				Path=RootContent & "Upload\"& cstr(bNam) &"\Duthao\Text"
				Path=Path & "\" & bMa & ".VT" 
			Case "4"
				Path=RootContent & "Upload\"& cstr(bNam) &"\Noibo\Text"
				Path=Path & "\" & bMa & ".VT"
'Hien 22_05
			Case "5"
				Path=RootContent & "Upload\"& cstr(bNam) &"\Quyetdinh\Text"
				Path=Path & "\" & replace(bMa,"/","_") & ".VT"
			Case "6"
				Path=RootContent & "Upload\"& cstr(bNam) &"\DenCB\Text"
				Path=Path & "\" & bMa & ".VT"
		End Select
		Set TextFile=server.CreateObject("Vinalines.ClsFile")		
		TextFile.SaveFile Request("Body"),Path		
		Set TextFile=nothing
	end if
	If bComm="remove" then
		Select Case bLoaiVT
			Case "1"
				f=RootContent &  "Upload/"& cstr(bNam) &"/Den/"
			Case "2"
				f=RootContent & "Upload/"& cstr(bNam) &"/Di/"
			Case "3"
				f=RootContent & "Upload/"& cstr(bNam) &"/DuThao/"
			Case "4"
				f=RootContent & "Upload/"& cstr(bNam) &"/Noibo/"
			Case "5"
				f=RootContent & "Upload/"& cstr(bNam) &"/Quyetdinh/"
			Case "6"
				f=RootContent & "Upload/"& cstr(bNam) &"/DenCB/"
'Hien24_06
			Case "7"
				f=RootContent & "Upload/"& cstr(bNam) &"/Totrinh/"
		End Select
		Items=request("Listbox")
		bLen=Len(ITems)
		i=1
		on error resume next
		Conn.BeginTrans
		Set File = Server.CreateObject("ActiveFile.File")
		Do while i<=bLen			
			It=mid(ITems,i,1)
			if It<>"," then
				Temp=Temp+It
			else						
				if bLen<>i then
					sSQL="Select Tentep from vanban_noidung where Mavanthu ='"& bMa &"' and LoaiVanthu = '"& bLoaiVT &"' and Sothutu =" & Temp & " order by sothutu"
					Set RecVB=server.CreateObject("ADODB.Recordset")
					RecVB.CursorType=3
					RecVB.CacheSize=5
					RecVB.Open sSQL,Conn				
					if RecVB.RecordCount then
						Path=f
'Hien 21_05
						File.Name=Path & "/" & replace(RecVB("Tentep"),"/","_")
						if File.Exists() then
							File.Delete()
						end if
					end if
					RecVB.Close
					Set RecVB=nothing
					sSQL="Delete from Vanban_Noidung Where Mavanthu ='"& bMa &"' and LoaiVanthu ='"& bLoaiVT &"' and Sothutu =" & Temp 
					Conn.Execute sSQL
					Temp=""
				end if
			end if
			if i=bLen then
				if i=1 then
					sSQL="Select Tentep from vanban_noidung where Mavanthu ='"& bMa &"' and LoaiVanthu = '"& bLoaiVT &"' and Sothutu =" & It & " order by sothutu"
				else
					sSQL="Select Tentep from vanban_noidung where Mavanthu ='"& bMa &"' and LoaiVanthu ='"& bLoaiVT &"' and Sothutu =" & Temp & " order by sothutu"				
				end if
				Set RecVB=server.CreateObject("ADODB.Recordset")
				RecVB.CursorType=3
				RecVB.CacheSize=5
				RecVB.Open sSQL,Conn
				if RecVB.RecordCount then							
					Path=f
'Hien 21_05
					File.Name=Path & "/" & replace(RecVB("Tentep"),"/","_")
					if File.Exists() then
						File.Delete()
					end if
				end if
				RecVB.Close
				Set RecVB=nothing
				sSQL="Delete from Vanban_Noidung Where Mavanthu ='"& bMa &"' and LoaiVanthu ='"& bLoaiVT &"' and Sothutu =" & Temp 
				Conn.Execute sSQL
			end if
			i=i+1
		Loop
		Set File=nothing
		if Err.number=0 then
			Conn.CommitTrans
		else
			Conn.RollbackTrans
		end if
	end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function frmupload_onsubmit()
{
	if (frmupload.UploadedFile.value=="")
		{
		alert("Bạn phải nhập đường dẫn !")
		frm.TxtMota.focus;
		return false;
		}
	else
		{
		UploadedFile_onfocus();
		return false;
		}
}
function frm_onsubmit()
{
	if (frm.TxtMota.value=="")
		{
		alert("Bạn phải mô tả nội dung");
		frm.CmdAttach.focus;
		return false;
		}
	else
		{
		CmdAttach_onclick();
		return false;
		}
}
function CmdBack_onclick() {
<%if bLoaiVT="7" then%>	
	frm.target="right";
	frm.action="../Xuly/frmTotrinh.asp?TxtID="+"<%=bMa%>"+"&bNam="+"<%=bNam%>"+"&bLoaiVT="+"<%=bLoaiVT%>"+"&bComm=edit"+"&sort="+frm.Sort.value;
	frm.submit();
<%else%>
	frm.target="right";
	frm.action="frmedit.asp?bMa="+"<%=bMa%>"+"&bNam="+"<%=bNam%>"+"&bLoaiVT="+"<%=bLoaiVT%>"+"&sort="+frm.Sort.value;
	frm.submit();
<%end if%>
}
function CmdAttach_onclick() {
	if(frmupload.UploadedFile.value==""){
		alert("Bạn cần phải chọn tệp");
		return false;
	}
	if(frm.TxtMota.value==""){
		alert("Cho biết mô tả nội dung");
		frm.TxtMota.focus();
		return false;
	}
	frmupload.target="right";
	frmupload.action="upload.asp?bMa="+"<%=bMa%>"+"&bNam="+"<%=bNam%>"+"&bLoaiVT="+"<%=bLoaiVT%>"+"&bMota="+frm.TxtMota.value+"&sort="+frm.Sort.value;
	frmupload.submit();
}	
function CmdRemove_onclick() {
	if(frm.ListBox.value==""){
		alert("Bạn cần phải chọn tệp loại bỏ");
		return false;
	}	
	frm.action="attach.asp?bComm=remove&bNam="+"<%=bNam%>"+"&bMa="+"<%=bMa%>"+"&bLoaiVT="+"<%=bLoaiVT%>";
	frm.submit();
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE=vbscript  >
sub UploadedFile_onfocus
	if frmupload.UploadedFile.value<>"" then
		k=1
		longpath =len(frmupload.UploadedFile.value)
		check=true
		while k<longpath and check
			bdau=instr(k,frmupload.UploadedFile.value,"\")
			if bdau > 0 then
				bcuoi=instr(bdau+1,frmupload.UploadedFile.value,"\")
				if bcuoi = 0 then
					frm.TxtMota.value=mid(frmupload.UploadedFile.value,bdau+1,longpath-bdau)
					check=false
				end if
			else
				'alert("Duong dan sai !")
				frm.TxtMota.value=""
				check=false
			end if
			k=bdau+1
		Wend
	else
	frm.TxtMota.value=""
	end if
end sub
sub CmdAttach_onfocus
	if trim(frm.TxtMota.value)="" then
		frm.TxtMota.value=""
	end if
end sub
</SCRIPT>
</head>
<body style="font-family: Arial" bgcolor=#F8F9D9>
<div align="center">
<%
	if request("Msg")="cancel" then
%><p align=center><font face="Times New Roman" size="3" color=red>L&#7895;i Attach File
<%end if%>
	<form name=frmupload method=post enctype="multipart/form-data" onsubmit="return frmupload_onsubmit()">
		<table border="0" width="600" cellspacing="0" cellpadding="0" height="158" bgcolor="#BDD5D0" bordercolor="#111111" style="Font-family:arial;font-size:11pt;BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;border-collapse:collapse; border-left-color:#C0C0C0; border-right-color:#C0C0C0; border-top-color:#C0C0C0; border-bottom-color:#C0C0C0">
		<TR>	     
			<TD width=610 colspan=3 bgcolor="#000080" height="19" width="530">     
	          <p align="center"><font color="#FFFFFF">Danh s&#225;ch t&#7879;p</font></p>     
	        </TD>     
		<tr>     
	    <td width="270" height="24" colspan="2">     
	      <p align="center">     
	          <input type="file" name="UploadedFile" style="width: 430; height: 23" size="20" ></p>     
	    </td>
	    </form>     
		<form name=frm method=post onsubmit="return frm_onsubmit()">
		<Input TYPE="hidden" name="Sort" value="<%=sort%>">
	    <td width="263" height="24">
	    </td>     
	  </tr>     
	  <tr>     
	    <td height="110" style="width:265"valign="top" align="center" rowspan="5" colspan="2">     
	        <p align="center">     
	    		<SELECT name=ListBox size=7 style="width:430;font-family:Arial" multiple>
	    		<%	
					Set Rec=server.CreateObject("ADODB.Recordset")
					sSQL="Select * from Vanban_Noidung where Mavanthu like '"& bMa &"' and LoaiVanthu like '"& bLoaiVT &"'"
					Rec.CursorType=3
					Rec.CacheSize=5
					Rec.Open sSQL,Conn
					STT=1
					Do while Not Rec.EOF
				%>
						<option value=<%=Rec("Sothutu")%>><%=Rec("Mota")%></option>
				<%
						Rec.MoveNext
					Loop
				%>
			</SELECT></p>
	    </td>     
		<td width="499" height="22">     
		</tr>
		<tr>
		<td width="499" height="22">     
	    <p align="center"><Input type=Button name=CmdAttach value="G&#7855;n t&#7879;p" style="family-font: Arial; width: 128; height: 23; font-family: Arial" LANGUAGE=javascript onclick ="return CmdAttach_onclick()">
	    </td>     
	  </tr>     
	  <tr>     
	    <td width="499" height="22">     
	    <p align="center"><Input type=Button name=CmdRemove value="Lo&#7841;i kh&#7887;i danh s&#225;ch" style="family-font: Arial; width: 128; height: 23; font-family: Arial" LANGUAGE=javascript onclick="return CmdRemove_onclick()">     
	    </td>     
	  </tr>     
	  <tr>     
	    <td width="499" height="22">     
	    <p align="center"><Input type=Button name=CmdBack value="Quay l&#7841;i" style="family-font: Arial; width: 128; height: 23; font-family: Arial" LANGUAGE=javascript onclick="return CmdBack_onclick()">
	    </td>     
	  </tr>     
	  <tr>     
	    <td width="499" height="22">     
	    </td>     
	  </tr>     
	  <tr>     
          <td height="25" nowrap vAlign="top" width="120"><center><font face="Arial">M&#244;     
            t&#7843; n&#7897;i dung</font></center></td>     
          <td height="25" vAlign="top" width="339">
          <input type ="text" name="TxtMota" size="46"  style="FONT-FAMILY: Arial"></td>
      </tr>
	</table>
</Form>
</div>
<%
	Conn.Close
	Set Conn=nothing
%> </font>
</body>
</html>